//
//  JPLoginLeftController.m
//  JPKY
//
//  Created by Vitas on 2016/11/14.
//  Copyright © 2016年 Vitas. All rights reserved.
//

#import "JPLoginLeftController.h"
#import "JPLoginView.h"
#import "JPRegistViewController.h"
#import "JPLoginViewController.h"

@interface JPLoginLeftController ()

/* 添加TableView */
@property (strong, nonatomic) UITableView *tableView;

@end

@implementation JPLoginLeftController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 设置表头视图
    [self setupHeader];
    
    // 监听注册广播
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(regist:) name:@"Regist" object:nil];
    
    // 监听登录广播
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(login:) name:@"Login" object:nil];
}

/**
 设置表头视图
 */
- (void)setupHeader {

    // 表头视图高度
    CGFloat height = 100.0;
    
    CGRect frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width *3.0/4.0f, height);
    
    UIView *headView = [[UIView alloc] init];
    headView.frame = frame;
    headView.backgroundColor = [UIColor clearColor];
    self.tableView.tableHeaderView = headView;
    
    // 添加tableView
    [self.view addSubview:self.tableView];
    
    // 添加头像View
    JPLoginView *loginView = [[JPLoginView alloc] init];
    
    loginView.frame = frame;
    
    [self.view addSubview:loginView];
    
}

#pragma mark - 响应监听注册与登录方法

- (void)regist:(NSNotification *)notification {
    
    JPRegistViewController *vc = [[JPRegistViewController alloc] init];
    vc.title = @"注册";
//    vc.view.backgroundColor =  [UIColor colorWithRed:arc4random_uniform(256) / 255.0 green:arc4random_uniform(256) / 255.0 blue:arc4random_uniform(256) / 255.0 alpha:1.0];
    UITabBarController *tab = (UITabBarController *)self.drawer.centerViewController;
    UINavigationController *nav = tab.selectedViewController;
    [nav popViewControllerAnimated:NO];
    [self.drawer close];
    [nav pushViewController:vc animated:NO];
}

- (void)login:(NSNotification *)notification {
    
    JPLoginViewController *vc = [[JPLoginViewController alloc] init];
        vc.title = @"登录";
//    vc.view.backgroundColor =  [UIColor colorWithRed:arc4random_uniform(256) / 255.0 green:arc4random_uniform(256) / 255.0 blue:arc4random_uniform(256) / 255.0 alpha:1.0];
    UITabBarController *tab = (UITabBarController *)self.drawer.centerViewController;
    UINavigationController *nav = tab.selectedViewController;
    [nav popViewControllerAnimated:NO];
    [self.drawer close];
    [nav pushViewController:vc animated:NO];
    
}

#pragma mark - 懒加载tableView
- (UITableView *)tableView{
    
    if (!_tableView ) {
        
        CGRect frame = CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width*3.0/4.0f, self.view.bounds.size.height);
        _tableView = [[UITableView alloc] initWithFrame: frame style:UITableViewStyleGrouped];
        

    }
    
    return _tableView;
}

- (void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
